//
//  UIButtonExtension.swift
//  hyjxweibo
//
//  Created by 姜永永 on 16/7/25.
//  Copyright © 2016年 com.primecocn. All rights reserved.
//

import Foundation
import UIKit

extension UIButton {
    //swift中类方法是以class开头的方法，类似于OC中的+开头的方法
    class func creatNewButton(imagName : String , bgImageName : String) -> UIButton {
        let btn = UIButton()
        btn.setImage(UIImage(named: imagName), forState: .Normal)
        btn.setImage(UIImage(named: imagName + "_highlighted"), forState: .Highlighted)
        btn.setBackgroundImage(UIImage(named: bgImageName), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: bgImageName + "_highlighted"), forState: .Highlighted)
        btn.sizeToFit()
        return btn
    }
    
    
    //convenience:便利，使用convenience修饰的构造函数叫做便利构造函数
    //便利构造函数通常用在对系统的类进行构造函数的扩充使用
    /*
      便利构造函数的特点
       1.便利构造函数通常写在extension里面
       2.便利构造函数init前面需要加convenience
       3.在便利构造函数中需要明确的调用self.init()
     */
    
    convenience init(imagName : String , bgImageName : String) {
        
        self.init()
        
        setImage(UIImage(named: imagName), forState: .Normal)
        setImage(UIImage(named: imagName + "_highlighted"), forState: .Highlighted)
        setBackgroundImage(UIImage(named: bgImageName), forState: .Normal)
        setBackgroundImage(UIImage(named: bgImageName + "_highlighted"), forState: .Highlighted)
        sizeToFit()
        
    }
    
    
    
    
    
    
    
}